package com.naxiang.cn.weight;

import android.app.Activity;
import android.content.Context;
import android.text.Editable;
import android.text.InputFilter;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.naxiang.cn.naxiangbackcard.R;

/**
 * 作者: 赵航
 * 创建时间: 2018/8/9 11:14
 * 描述:
 */
public class WithdrawCash extends RelativeLayout {
    private RelativeLayout mLayout;
    private LinearLayout mHandLine;
    private ImageView mCashIocn;
    private TextView mCashType;
    private EditText mCashMoney;
    private Button mCashAll;
    private Button mCashBingin;
    private TextView mBalanceMoney;
    public WithdrawCash(Context context) {
        super(context);
        initView();
    }

    public WithdrawCash(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    private void initView() {

        LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        mLayout = (RelativeLayout) inflater.inflate(R.layout.mo_naxiangbackcard_cash_layout, this);
        mHandLine=(LinearLayout)mLayout.findViewById(R.id.chengecashcard);
        mCashIocn=(ImageView) mLayout.findViewById(R.id.cashbankicon);
        mCashType=(TextView)mLayout.findViewById(R.id.cashcardtype);
        mCashMoney=(EditText)mLayout.findViewById(R.id.cashmoney);
        mCashAll= (Button) mLayout.findViewById(R.id.cashallmoney);
        mCashBingin= (Button)mLayout.findViewById(R.id.cashbigin);
        mBalanceMoney=(TextView)mLayout.findViewById(R.id.balancemoney);



        //设置Input的类型过滤
        mCashMoney.setFilters(new InputFilter[]{new InputFilter() {
            @Override
            public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
                if (source.equals(".") && dest.toString().length() == 0) {
                    ToastMaked.showToast(getContext(), "第一位数字不能为点");
                    return "";
                }
                if (source.equals("0") && dest.toString().length() == 0) {
                    ToastMaked.showToast(getContext(), "首位数字不能为0");
                    return "";
                }
                if (source.equals(".")){
                    ToastMaked.showToast(getContext(), "提现的钱数只能为100的倍数");
                    return "";
                }
                return null;
            }
        }});
        mCashBingin.setEnabled(false);

        //设置按钮监听事件
        mCashMoney.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (s.length() > 0) {
                    mCashBingin.setEnabled(true);
                    mCashMoney.setTextSize(30);
                } else {
                    mCashBingin.setEnabled(false);
                    mCashMoney.setTextSize(18);
                }


            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });



    }
    public ImageView getCashIocn() {
        return mCashIocn;
    }

    public TextView getCashType() {
        return mCashType;
    }

    public EditText getCashMoney() {
        return mCashMoney;
    }

    public Button getCashAll() {
        return mCashAll;
    }

    public Button getCashBingin() {
        return mCashBingin;
    }

    public LinearLayout getHandLine() {
        return mHandLine;
    }
    public TextView getBalanceMoney() {
        return mBalanceMoney;
    }

}
